local weishe = fk.CreateSkill {
  name = "ls__weishe",
  dynamic_desc = function(self, player)
    if #player:getTableMark("ls__weishe-round") >= 2 then
      return "dummyskill"
    end
    local texts = {"ls__weishe_inner", "ls__weishe1", "ls__weishe2", "ls__weishe3", "ls__weishe_tail"}
    if table.contains(player:getTableMark("ls__weishe-round"), "weishe_lose") then
      texts[2] = "<font color='grey'><s>"..Fk:translate("ls__weishe1").."</s></font>"
    end
    if table.contains(player:getTableMark("ls__weishe-round"), "weishe_recover") then
      texts[4] = "<font color='grey'><s>"..Fk:translate("ls__weishe3").."</s></font>"
    end
    return table.concat(texts, ":")
  end,
}

Fk:loadTranslationTable{
  ["ls__weishe"] = "威赦",
  [":ls__weishe"] = "每轮各限一次，当其他角色的体力值变为和你相同后，你可令其回复或失去1点体力。",
  ["#ls__weishe-invoke"] = "威赦：你可以令%src失去或回复1点体力",
  ["lose_hp"] = "失去体力",
  ["recover_hp"] = "回复体力",
  [":ls__weishe_inner"] = "每轮各限一次，当其他角色的体力值变为和你相同后，你可令其{1}{2}{3}{4}",
  ["ls__weishe1"] = "失去",
  ["ls__weishe2"] = "或",
  ["ls__weishe3"] = "回复",
  ["ls__weishe_tail"] = "1点体力。",

  ["$ls__weishe1"] = "（回复）这是本王，最后的仁慈。",
  ["$ls__weishe2"] = "（失去）比丧命更痛苦，比死亡更恐怖。",
}

weishe:addEffect(fk.HpChanged, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(weishe.name) and target.hp == player.hp
    and #player:getTableMark("ls__weishe-round") < 2
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {}
    if not table.contains(player:getTableMark("ls__weishe-round"), "weishe_lose") then
      table.insertIfNeed(choices, "lose_hp")
    end
    if target:isWounded() and not table.contains(player:getTableMark("ls__weishe-round"), "weishe_recover") and not target.dead then
      table.insertIfNeed(choices, "recover_hp")
    end
    local choice = room:askToChoice(player, { choices = choices, skill_name = weishe.name, all_choices = {"lose_hp","recover_hp"} })
    if choice == "lose_hp" then
      room:addTableMarkIfNeed(player, "ls__weishe-round", "weishe_lose")
      room:notifySkillInvoked(player, weishe.name, "offensive")
      player:broadcastSkillInvoke(weishe.name, 2)
      room:loseHp(target)
    else
      room:addTableMarkIfNeed(player, "ls__weishe-round", "weishe_recover")
      room:notifySkillInvoked(player, weishe.name, "support")
      player:broadcastSkillInvoke(weishe.name, 1)
      room:recover{ who = target, num = 1, skillName = weishe.name }
    end    
  end,
})

return weishe